﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ShopOnline.Models.DAL
{
    public class DAL_Picture
    {
         private ShopOnline.Models.ShopOnlineDBDataContext SC_DB;
         public DAL_Picture()
        {
            SC_DB = new ShopOnlineDBDataContext();
        }


        public List<Picture> getListPicture()
        {
           return SC_DB.Pictures.ToList();
        }


        public Picture getPictureById(int PictureId)
        {
            return (from c in SC_DB.Pictures where c.pictureId==PictureId select c).FirstOrDefault();
        }

        public int CreatePicture(Picture Picture)
        {
            int result = 0;
            try
            {
                SC_DB.Pictures.InsertOnSubmit(Picture);
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }

        public int EditCatlogy(Picture pre)
        {
            int result = 0;
            try
            {
                var Picture = (from c in SC_DB.Pictures where c.pictureId == pre.pictureId select c).FirstOrDefault();
                Picture.body = pre.body;
                Picture.curent = pre.curent;
                Picture.description = pre.description;
                Picture.imagePath = pre.imagePath;
                Picture.show = pre.show;
                Picture.title = pre.title;
                Picture.url = pre.url;
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }
        public int DeletePicture(Picture Picture)
        {
            int result = 0;
            try
            {
                var pic = (from c in SC_DB.Pictures where c.pictureId == Picture.pictureId select c).FirstOrDefault();
                SC_DB.Pictures.DeleteOnSubmit(Picture);
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }
    }
}